<template>
    <div id="products">
        <baseinfo></baseinfo>
        <div class="title">
            <i class="el-icon-star-on"></i>
            <span>{{getType(this.$route.query.msg)}}</span>
            <i class="el-icon-star-on"></i>
        </div>
        <div class="showpro">
        
        <productBrief
        v-for="item in products"
        :key="item.index" 
        :image="item.image"
        :name="item.name"
        :price="item.price"
        :sellername="item.sellerUsername"
        :id="item.id"
        ></productBrief>
        <!-- <productBrief
        v-for="item in 10"
        :key="item.index"
        image="https://img13.360buyimg.com/jdcms/s300x300_jfs/t1/178661/28/3905/138182/609d39a7Eb1a7b045/c6f860d88ffe3ffd.jpg.webp"
        name="百草味 冰雪蛋糕540g/箱
                网红饼干糕点点心整箱早餐手撕小面包麻薯夹心糯米糍"
        price="99.9"
        sellername="百草味官方旗舰店"
        id="3"
        ></productBrief> -->
      </div>
    </div>
</template>

<script>
import {request} from '../network/request';
import baseinfo from '../components/baseinfo.vue'
import productBrief from '../components/productBrief.vue'

export default {
    data(){
        return {
            products:'',
            type:''
        }
    },
    components: {
        baseinfo, productBrief
    },
    watch:{
        $route(){
            this.type = this.$route.query.msg
            this.update()
        }
    },
    created(){
        request({
            url:'/products',
            method: 'get',
            params: {
                type: this.$route.query.msg
            }
        }).then(res => {
            this.products = res.data.products
        })
    },
    methods: {
        update(){
            request({
                url:'/products',
                method: 'get',
                params: {
                    type: this.type
                }
            }).then(res => {
                this.products = res.data.products
            })
        },
        getType(type){
            switch(type){
                case "1":
                return "电子产品"
                case "2":
                return "学习文具"
                case "3":
                return "生活用品"
                case "4":
                return "美妆服饰"
                case "5":
                return "教材图书"
                case "6":
                return "食品饮料"
                case "7":
                return "精美礼品"
                case "8":
                return "休闲娱乐"
                case "9":
                return "其他"
            }
        }
    }
}
</script>

<style scoped>

.title {
    text-align: center;
    font-size: 28px;
    font-weight: bold;
    padding-top: 25px;
    padding-bottom: 20px;
    margin: 0 auto;
    display: flex;
    justify-content: space-around;
    width: 200px;
}

.title i {
    padding: 5px;
}

.showpro {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
}

</style>